package encaps.utils.rendering;

import encaps.resources.Response;
import encaps.utils.StringUtil;
import static encaps.utils.html.HTML.NAME;
import static encaps.utils.html.HTML.SIZE;
import encaps.utils.html.HTMLElement;
import encaps.utils.html.HTMLElementSequence;
import org.jdom.Element;

public class SelectFactory extends AbstractSelectFactory {

    @Override
    public HTMLElement renderField(Element e, boolean edit) {
        HTMLElementSequence result = new HTMLElementSequence();
        HTMLElement select = super.renderField(e, edit);
        String label = e.getChildTextTrim(Response.MESSAGE);

        String selectKey = e.getChildTextTrim(Response.LABEL);
        select.addAttribute(SIZE, 1);
        select.addAttribute(NAME, selectKey);

        if (!StringUtil.isEmpty(label)) {
            result.addContent(HTMLElement.createB(label + ": "));
        }
        result.addContent(select);
        result.addContent(HTMLElement.createBr());
        return result;

    }
}
